<?php
namespace BoxSns\Controller\Home;
class CommonController extends \HomeController
{
    public function _initialize()
    {
        parent::_initialize();
        $this->user_id = session('user_id');
        $this->user_info = BoxModel("system_member")->load($this->user_id);
        $this->user_info_json = json_encode($this->user_info);
        /*if(!$this->user_info['user_id']){
               Logic("BoxSns","Member")->toLogin();
        }*/
        /* if($this->user_id){
            $this->my_user_statistics=Logic("BoxSns","Member")->statistics(array('user_id'=>$this->user_id,'store_id'=>$this->store_id));
         }*/
        $this->title = "社区";

    }


    /****display模板***/
    public function display($dir)
    {
        $templateFile = $this->getTemplateFile("Index/home");
        $this->page_content = self::fetch($dir);
        parent::display($templateFile);
    }

    public function  getTemplateFile($templateFile)
    {
        $tpl = BOX_MODULE_NAME;
        C('DEFAULT_MODULE', "BoxSns");
        if ($this->is_mobile) {
            $tpl = "Wap";
        }
        C('DEFAULT_V_LAYER', "View/" . $tpl);
        if ($templateFile == "" || !is_file($templateFile)) {
            $depr = C('TMPL_FILE_DEPR');
            $c_name = CONTROLLER_NAME;
            if (strpos(CONTROLLER_NAME, '/')) { // 指定参数来源
                list($method, $c_name) = explode('/', $c_name, 2);
            }
            if (!$templateFile) {
                $templateFile = $c_name . $depr . ACTION_NAME;
            }
        }
        $File = "./Apps/" . C('DEFAULT_MODULE') . "/View/" . $tpl . "/" . $templateFile . C('TMPL_TEMPLATE_SUFFIX');
        if ($tpl != "Home" && is_file($File)) {
            return $File;
        } else {
            return "./Apps/" . C('DEFAULT_MODULE') . "/View/Home/" . $templateFile . C('TMPL_TEMPLATE_SUFFIX');
        }

    }

    /****fetch模板***/
    public function fetch($templateFile, $content = '', $prefix = '')
    {
        $templateFile = $this->getTemplateFile($templateFile);
        return parent::fetch($templateFile, $content, $prefix);
    }


    /*****用户中心页面***/
    function show_user($page)
    {
        $templateFile = $this->getTemplateFile("User/home");
        $this->page_content = self::fetch($page);
        if (IS_AJAX) {
									 if ($GLOBALS['GETCONTENT']) {
									  $user_public_content = self::fetch("Public/user_public");
           $this->page_content .= $user_public_content;
										}
            echo $this->page_content;
												if(I('requestFrom')=='modal'){
														exit();
												}
        } else {
            if ($GLOBALS['GETCONTENT']) {
                $user_public_content = self::fetch("Public/user_public");
                $this->page_content .= $user_public_content;
                echo $this->page_content;
            } else {
                parent::display($templateFile);
            }
        }
    }


}

 